/*
 * PagosContribuyentesFijosFrame.java
 *
 * Created on 13 de abril de 2008, 11:44 AM
 */
package org.contabilidad.recibos.anular;

import org.mybeans.Sesion;
 
import org.mybeans.ArregloPagoBeans;
import org.mybeans.ComerciosInscripcionBeans;
import org.mybeans.MorosidadMensualBeans;
import org.mybeans.PagosAnualesBeans;
import org.mybeans.PagosMensualesBeans;
import org.mybeans.RecargoMensualBeans;
import org.mybeans.RecibesAnuladosBeans;
import org.mybeans.RecibesBeans;
import org.mybeans.RecibesDetallesBeans;

import org.mybeans.VigenciasExpiradasBeans;
import java.sql.PreparedStatement;
import java.text.SimpleDateFormat;
import javax.swing.JLabel;
import javax.swing.JOptionPane;
import javax.swing.table.DefaultTableModel;
import javax.swing.table.TableColumn;

/**
 *
 * @author  avbravo
 */
public class RecibosAnularFrame extends javax.swing.JFrame {

    boolean focoContribuyente = false;
    String reportSource;
    String reportDest;
    ArregloPagoBeans arregloPagoBeans;
    ComerciosInscripcionBeans comerciosInscripcionBeans;
    MorosidadMensualBeans morosidadMensualBeans;
    PagosMensualesBeans pagosMensualesBeans;
    PagosAnualesBeans pagosAnualesBeans;
    RecibesBeans recibesBeans;
    RecibesDetallesBeans recibesDetallesBeans;
    RecibesAnuladosBeans recibesAnuladosBeans;
    RecargoMensualBeans recargoMensualBeans;
    Sesion sesion;
    VigenciasExpiradasBeans vigenciasExpiradasBeans;
    int fila = -1;
    DefaultTableModel modelo;
    private int AnioRecibo;
    private int NumeroMes;
    String Id;
    String TipoId = "";
    private String idRegimen;
    double SoloMorosidad = 0.0;
    double SaldoAnterior = 0.0;
    String sql;
    String rowIdRegimen;
    String rowRegimen;
    double rowValor;
    double rowPago;
    int rowCantidad;
    double rowExoneracion;
    double rowSaldo;
    double rowSaldoAnterior;
    String rowEsRecargo;
    String rowComentario;
    String rowEstatus;
    String rowPeriodo;
    double rowSoloMorosidad;
    double Pago = 0;
    double Exoneracion = 0;
    double Valor = 0.0;
    double Saldo = 0.0;
    int IdRecibo = 0;
    Double TotalPagado = 0.0;
    Double TotalExonerado = 0.0;
    String idExoneracion = "";
    Double Deuda;
    boolean TieneExoneracion = false;
    boolean TieneAlgunRegistroMoroso = false;
    String Estatus;
    int n;
    int paginas;
    String TipoRecibo;

    /** Creates new form */
    public RecibosAnularFrame() {
        initComponents();
        sesion = new Sesion();
        
        /*
         * Fondo
         */

         
         
         

        jPanelFondo.setOpaque(false);
        setContentPane(jPanelFondo);
        /*
         * fondo
         */
        arregloPagoBeans = new ArregloPagoBeans();
        comerciosInscripcionBeans = new ComerciosInscripcionBeans();
        morosidadMensualBeans = new MorosidadMensualBeans();
        pagosAnualesBeans = new PagosAnualesBeans();
        pagosMensualesBeans = new PagosMensualesBeans();
        recibesBeans = new RecibesBeans();
        recibesDetallesBeans = new RecibesDetallesBeans();
        recibesAnuladosBeans = new RecibesAnuladosBeans();
        recargoMensualBeans = new RecargoMensualBeans();

        vigenciasExpiradasBeans = new VigenciasExpiradasBeans();

        java.util.Calendar ca = java.util.Calendar.getInstance();
        java.sql.Date mydate = new java.sql.Date(ca.getTimeInMillis());
        jFormattedTextFieldFecha.setValue(mydate);


        jXDatePickerFechaAnulacion.setDate(mydate);
        jXDatePickerFechaAnulacion.setFormats(new SimpleDateFormat("dd/MM/yyyy"));

        this.AnioRecibo = ca.get(java.util.Calendar.YEAR);
        NumeroMes = ca.get(java.util.Calendar.MONTH);

        sesion.setAnioRecibo(AnioRecibo);
        sesion.setNumeroMesRecibo(NumeroMes);
        //
        modelo = (DefaultTableModel) jXTable1.getModel();

        modelo.isCellEditable(1, 1);
        TableColumn columnCheckBox = jXTable1.getColumnModel().getColumn(0);
        columnCheckBox.setPreferredWidth(2);

        TableColumn columnId = jXTable1.getColumnModel().getColumn(1);
        columnId.setPreferredWidth(130);

        TableColumn columnRegimen = jXTable1.getColumnModel().getColumn(2);
        columnRegimen.setPreferredWidth(130);



        jTextFieldTotalExonerado.setText("");
        jTextFieldTotalPago.setText("");




    }

    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jPanelFondo = new javax.swing.JPanel();
        jLabel2 = new javax.swing.JLabel();
        jTextFieldRecibo = new javax.swing.JTextField();
        jLabel3 = new javax.swing.JLabel();
        jFormattedTextFieldFecha = new javax.swing.JFormattedTextField();
        jButtonRegresar = new javax.swing.JButton();
        jLabel4 = new javax.swing.JLabel();
        jTextFieldIdPagador = new javax.swing.JTextField();
        jLabel5 = new javax.swing.JLabel();
        jTextFieldNombrePagador = new javax.swing.JTextField();
        jLabel1 = new javax.swing.JLabel();
        jScrollPane2 = new javax.swing.JScrollPane();
        jXTable1 = new org.jdesktop.swingx.JXTable();
        jLabel18 = new javax.swing.JLabel();
        jTextFieldTotalPago = new javax.swing.JTextField();
        jLabel6 = new javax.swing.JLabel();
        jTextFieldTotalExonerado = new javax.swing.JTextField();
        jButtonLimpiar = new javax.swing.JButton();
        jButtonRegresar2 = new javax.swing.JButton();
        jTextFieldExoneracion = new javax.swing.JTextField();
        jTextFieldTipoRecibo = new javax.swing.JTextField();
        jLabel7 = new javax.swing.JLabel();
        jTextFieldNombreFuncionario = new javax.swing.JTextField();
        jSeparator1 = new javax.swing.JSeparator();
        jLabel8 = new javax.swing.JLabel();
        jXDatePickerFechaAnulacion = new org.jdesktop.swingx.JXDatePicker();
        jLabel9 = new javax.swing.JLabel();
        jTextFieldAutorizadoPor = new javax.swing.JTextField();
        jLabel10 = new javax.swing.JLabel();
        jScrollPane1 = new javax.swing.JScrollPane();
        jTextAreaMotivo = new javax.swing.JTextArea();
        jButtonAnular = new javax.swing.JButton();

        setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);
        setTitle("ANULAR  RECIBOS");
        addWindowFocusListener(new java.awt.event.WindowFocusListener() {
            public void windowGainedFocus(java.awt.event.WindowEvent evt) {
                formWindowGainedFocus(evt);
            }
            public void windowLostFocus(java.awt.event.WindowEvent evt) {
            }
        });

        jPanelFondo.setBorder(javax.swing.BorderFactory.createEtchedBorder());
        jPanelFondo.setOpaque(false);

        jLabel2.setText("Recibo");

        jTextFieldRecibo.setToolTipText("Numero de recibo");
        jTextFieldRecibo.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jTextFieldReciboActionPerformed(evt);
            }
        });

        jLabel3.setText("Fecha");

        jFormattedTextFieldFecha.setEditable(false);
        jFormattedTextFieldFecha.setFormatterFactory(new javax.swing.text.DefaultFormatterFactory(new javax.swing.text.DateFormatter(new java.text.SimpleDateFormat("dd/MM/yyyy"))));
        jFormattedTextFieldFecha.setToolTipText("Fecha");
        jFormattedTextFieldFecha.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jFormattedTextFieldFechaActionPerformed(evt);
            }
        });

        jButtonRegresar.setIcon(new javax.swing.ImageIcon(getClass().getResource("/gif/regresar.jpeg"))); // NOI18N
        jButtonRegresar.setToolTipText("Regresar");
        jButtonRegresar.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButtonRegresarActionPerformed(evt);
            }
        });

        jLabel4.setText("Por");

        jTextFieldIdPagador.setColumns(35);
        jTextFieldIdPagador.setToolTipText("Cedula del contribuyente");
        jTextFieldIdPagador.setEnabled(false);
        jTextFieldIdPagador.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jTextFieldIdPagadorControlActionPerformed(evt);
            }
        });
        jTextFieldIdPagador.addKeyListener(new java.awt.event.KeyAdapter() {
            public void keyPressed(java.awt.event.KeyEvent evt) {
                jTextFieldIdPagadorKeyPressed(evt);
            }
        });

        jLabel5.setText("Tipo");

        jTextFieldNombrePagador.setColumns(70);
        jTextFieldNombrePagador.setEnabled(false);

        jLabel1.setText("Exoneracion");

        jScrollPane2.setHorizontalScrollBarPolicy(javax.swing.ScrollPaneConstants.HORIZONTAL_SCROLLBAR_ALWAYS);
        jScrollPane2.setVerticalScrollBarPolicy(javax.swing.ScrollPaneConstants.VERTICAL_SCROLLBAR_ALWAYS);

        jXTable1.setModel(new javax.swing.table.DefaultTableModel(
            new Object [][] {

            },
            new String [] {
                ".", "Codigo", "Regimen", "Deuda", "Cantidad", "Pago", "Saldo", "Exoneracion", "Estatus", "Periodo", "Valor", "Morosidad", "Comentario"
            }
        ) {
            Class[] types = new Class [] {
                java.lang.Boolean.class, java.lang.String.class, java.lang.String.class, java.lang.Double.class, java.lang.Integer.class, java.lang.Double.class, java.lang.Double.class, java.lang.Double.class, java.lang.String.class, java.lang.String.class, java.lang.Double.class, java.lang.Double.class, java.lang.String.class
            };
            boolean[] canEdit = new boolean [] {
                true, false, false, false, false, false, false, false, false, false, false, false, false
            };

            public Class getColumnClass(int columnIndex) {
                return types [columnIndex];
            }

            public boolean isCellEditable(int rowIndex, int columnIndex) {
                return canEdit [columnIndex];
            }
        });
        jXTable1.setOpaque(false);
        jScrollPane2.setViewportView(jXTable1);

        jLabel18.setText("Total");

        jTextFieldTotalPago.setEnabled(false);
        jTextFieldTotalPago.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jTextFieldTotalPagoActionPerformed(evt);
            }
        });

        jLabel6.setText("Total Exonerado");

        jTextFieldTotalExonerado.setEnabled(false);

        jButtonLimpiar.setIcon(new javax.swing.ImageIcon(getClass().getResource("/gif/escoba.png"))); // NOI18N
        jButtonLimpiar.setToolTipText("Limpiar");
        jButtonLimpiar.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButtonLimpiarActionPerformed(evt);
            }
        });

        jButtonRegresar2.setIcon(new javax.swing.ImageIcon(getClass().getResource("/gif/regresar.jpeg"))); // NOI18N
        jButtonRegresar2.setToolTipText("Regresar");
        jButtonRegresar2.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButtonRegresar2ActionPerformed(evt);
            }
        });

        jTextFieldExoneracion.setEnabled(false);

        jTextFieldTipoRecibo.setEnabled(false);

        jLabel7.setText("Funcionario");

        jTextFieldNombreFuncionario.setEnabled(false);

        jLabel8.setText("Fecha Anulacion");

        jLabel9.setText("Autorizado por");

        jLabel10.setText("Motivo");

        jTextAreaMotivo.setColumns(20);
        jTextAreaMotivo.setRows(5);
        jScrollPane1.setViewportView(jTextAreaMotivo);

        jButtonAnular.setIcon(new javax.swing.ImageIcon(getClass().getResource("/gif/save.png"))); // NOI18N
        jButtonAnular.setToolTipText("Guardar");
        jButtonAnular.setEnabled(false);
        jButtonAnular.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButtonAnularActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout jPanelFondoLayout = new javax.swing.GroupLayout(jPanelFondo);
        jPanelFondo.setLayout(jPanelFondoLayout);
        jPanelFondoLayout.setHorizontalGroup(
            jPanelFondoLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanelFondoLayout.createSequentialGroup()
                .addGroup(jPanelFondoLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(jPanelFondoLayout.createSequentialGroup()
                        .addContainerGap()
                        .addComponent(jLabel5)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(jTextFieldTipoRecibo, javax.swing.GroupLayout.PREFERRED_SIZE, 299, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(jLabel1)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(jTextFieldExoneracion, javax.swing.GroupLayout.PREFERRED_SIZE, 298, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addGroup(jPanelFondoLayout.createSequentialGroup()
                        .addGap(5, 5, 5)
                        .addComponent(jLabel2)
                        .addGap(14, 14, 14)
                        .addComponent(jTextFieldRecibo, javax.swing.GroupLayout.PREFERRED_SIZE, 100, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addGap(117, 117, 117)
                        .addComponent(jLabel3)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(jFormattedTextFieldFecha, javax.swing.GroupLayout.PREFERRED_SIZE, 135, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(jButtonRegresar, javax.swing.GroupLayout.PREFERRED_SIZE, 41, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addGroup(jPanelFondoLayout.createSequentialGroup()
                        .addContainerGap()
                        .addComponent(jLabel4)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(jTextFieldIdPagador, javax.swing.GroupLayout.PREFERRED_SIZE, 174, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addGap(18, 18, 18)
                        .addComponent(jTextFieldNombrePagador, javax.swing.GroupLayout.PREFERRED_SIZE, 341, javax.swing.GroupLayout.PREFERRED_SIZE)))
                .addContainerGap())
            .addGroup(jPanelFondoLayout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jLabel7)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jTextFieldNombreFuncionario, javax.swing.GroupLayout.PREFERRED_SIZE, 293, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap(780, Short.MAX_VALUE))
            .addGroup(jPanelFondoLayout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jScrollPane2, javax.swing.GroupLayout.DEFAULT_SIZE, 1146, Short.MAX_VALUE)
                .addContainerGap())
            .addGroup(jPanelFondoLayout.createSequentialGroup()
                .addComponent(jLabel18)
                .addGap(18, 18, 18)
                .addComponent(jTextFieldTotalPago, javax.swing.GroupLayout.PREFERRED_SIZE, 171, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 193, Short.MAX_VALUE)
                .addComponent(jLabel6)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jTextFieldTotalExonerado, javax.swing.GroupLayout.PREFERRED_SIZE, 160, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(482, 482, 482))
            .addGroup(jPanelFondoLayout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jSeparator1, javax.swing.GroupLayout.DEFAULT_SIZE, 504, Short.MAX_VALUE)
                .addGap(654, 654, 654))
            .addGroup(jPanelFondoLayout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanelFondoLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jLabel8)
                    .addComponent(jLabel9)
                    .addComponent(jLabel10))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jPanelFondoLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jXDatePickerFechaAnulacion, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jTextFieldAutorizadoPor, javax.swing.GroupLayout.PREFERRED_SIZE, 319, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addContainerGap(723, Short.MAX_VALUE))
            .addGroup(jPanelFondoLayout.createSequentialGroup()
                .addGap(78, 78, 78)
                .addComponent(jButtonAnular, javax.swing.GroupLayout.PREFERRED_SIZE, 80, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(23, 23, 23)
                .addComponent(jButtonLimpiar, javax.swing.GroupLayout.PREFERRED_SIZE, 80, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(18, 18, 18)
                .addComponent(jButtonRegresar2, javax.swing.GroupLayout.PREFERRED_SIZE, 74, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap(817, Short.MAX_VALUE))
        );
        jPanelFondoLayout.setVerticalGroup(
            jPanelFondoLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanelFondoLayout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanelFondoLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(jPanelFondoLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                        .addComponent(jFormattedTextFieldFecha, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addComponent(jButtonRegresar))
                    .addGroup(jPanelFondoLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                        .addComponent(jTextFieldRecibo, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addComponent(jLabel2)
                        .addComponent(jLabel3)))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jPanelFondoLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jTextFieldIdPagador, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jLabel4)
                    .addComponent(jTextFieldNombrePagador, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jPanelFondoLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel5)
                    .addComponent(jLabel1)
                    .addComponent(jTextFieldExoneracion, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jTextFieldTipoRecibo, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(7, 7, 7)
                .addGroup(jPanelFondoLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel7)
                    .addComponent(jTextFieldNombreFuncionario, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jScrollPane2, javax.swing.GroupLayout.PREFERRED_SIZE, 139, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(18, 18, 18)
                .addGroup(jPanelFondoLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel18)
                    .addComponent(jTextFieldTotalPago, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jLabel6)
                    .addComponent(jTextFieldTotalExonerado, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jSeparator1, javax.swing.GroupLayout.PREFERRED_SIZE, 10, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jPanelFondoLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel8)
                    .addComponent(jXDatePickerFechaAnulacion, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jPanelFondoLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel9)
                    .addComponent(jTextFieldAutorizadoPor, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jPanelFondoLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jLabel10)
                    .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 81, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jPanelFondoLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                    .addComponent(jButtonLimpiar, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addComponent(jButtonRegresar2, javax.swing.GroupLayout.DEFAULT_SIZE, 43, Short.MAX_VALUE)
                    .addComponent(jButtonAnular, javax.swing.GroupLayout.DEFAULT_SIZE, 43, Short.MAX_VALUE))
                .addGap(32, 32, 32))
        );

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addComponent(jPanelFondo, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(jPanelFondo, javax.swing.GroupLayout.DEFAULT_SIZE, 584, Short.MAX_VALUE)
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents

private void jButtonRegresarActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButtonRegresarActionPerformed

    this.dispose();
}//GEN-LAST:event_jButtonRegresarActionPerformed

private void jFormattedTextFieldFechaActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jFormattedTextFieldFechaActionPerformed
}//GEN-LAST:event_jFormattedTextFieldFechaActionPerformed

private void jButtonRegresar2ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButtonRegresar2ActionPerformed

    dispose();
}//GEN-LAST:event_jButtonRegresar2ActionPerformed

private void jTextFieldTotalPagoActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jTextFieldTotalPagoActionPerformed
}//GEN-LAST:event_jTextFieldTotalPagoActionPerformed

private void jButtonLimpiarActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButtonLimpiarActionPerformed

    Limpiar();

}//GEN-LAST:event_jButtonLimpiarActionPerformed

private void jTextFieldReciboActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jTextFieldReciboActionPerformed
    ValidarRecibos();
}//GEN-LAST:event_jTextFieldReciboActionPerformed

private void jTextFieldIdPagadorKeyPressed(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_jTextFieldIdPagadorKeyPressed
}//GEN-LAST:event_jTextFieldIdPagadorKeyPressed

private void jTextFieldIdPagadorControlActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jTextFieldIdPagadorControlActionPerformed
}//GEN-LAST:event_jTextFieldIdPagadorControlActionPerformed

    private void ValidarRecibos() {
        try {
            LimpiarTable();

            String SidRecibo = this.jTextFieldRecibo.getText();
            if (SidRecibo == null || SidRecibo.equals("")) {
                JOptionPane.showMessageDialog(this, "Debe ingresar un numero de recibo ", "Mensaje", JOptionPane.WARNING_MESSAGE);
                return;
            }
            this.IdRecibo = Integer.parseInt(SidRecibo);
            recibesBeans.setIdRecibo(IdRecibo);
            if (recibesBeans.ConsultarRecibo() == true) {
                CargarRecibos();

            }

        } catch (Exception ex) {
            JOptionPane.showMessageDialog(this, "Error " + ex.getMessage(), "Error", JOptionPane.ERROR_MESSAGE);
        }
    }
private void formWindowGainedFocus(java.awt.event.WindowEvent evt) {//GEN-FIRST:event_formWindowGainedFocus
    // TODO add your handling code here:
}//GEN-LAST:event_formWindowGainedFocus

private void jButtonAnularActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButtonAnularActionPerformed
    // TODO add your handling code here:
    try {
        String SIdRecibo = this.jTextFieldRecibo.getText();
        if (SIdRecibo == null || SIdRecibo.equals("")) {
            JOptionPane.showMessageDialog(this, "Ingrese el numero de recibo a anular", "Mensaje", JOptionPane.INFORMATION_MESSAGE);
            jTextFieldRecibo.requestFocus();
            return;
        }
        this.IdRecibo = Integer.parseInt(SIdRecibo);
        String NombrePagador = jTextFieldNombrePagador.getText();
        if (NombrePagador == null || NombrePagador.equals("")) {
            JOptionPane.showMessageDialog(this, "Ingrese el numero de recibo a anular", "Mensaje", JOptionPane.INFORMATION_MESSAGE);
            jTextFieldRecibo.requestFocus();
            return;
        }

        String Autorizado = jTextFieldAutorizadoPor.getText();
        if (Autorizado == null || Autorizado.equals("")) {
            JOptionPane.showMessageDialog(this, "Ingrese el nombre de quien autoriza", "Mensaje", JOptionPane.INFORMATION_MESSAGE);
            jTextFieldAutorizadoPor.requestFocus();
            return;
        }
        String Motivo = jTextAreaMotivo.getText();
        if (Motivo == null || Motivo.equals("")) {
            JOptionPane.showMessageDialog(this, "Ingrese el motivo", "Mensaje", JOptionPane.INFORMATION_MESSAGE);
            jTextAreaMotivo.requestFocus();
            return;
        }

        java.util.Date FechaDate = jXDatePickerFechaAnulacion.getDate();
        java.sql.Date FechaAnulacion = new java.sql.Date(FechaDate.getTime());
        if (FechaAnulacion == null) {
            JOptionPane.showMessageDialog(this, "Ingrese la fecha de anulacion", "Mensaje", JOptionPane.INFORMATION_MESSAGE);
            jXDatePickerFechaAnulacion.requestFocus();
            return;
        }
        int res = JOptionPane.showConfirmDialog(this, "Desea ANULAR el recibo",
                "Anular Recibo ", JOptionPane.YES_NO_OPTION);
        if (res == JOptionPane.NO_OPTION) {
            JOptionPane.showMessageDialog(this, "No se anulara el recibo", "Mensaje", JOptionPane.INFORMATION_MESSAGE);
            return;
        }
        java.util.Date myFecha = (java.util.Date) jFormattedTextFieldFecha.getValue();
        java.sql.Date date = new java.sql.Date(myFecha.getTime());
        recibesAnuladosBeans.setFecha(date);
        recibesAnuladosBeans.setIdRecibo(IdRecibo);
        recibesAnuladosBeans.setFechaAnulacion(FechaAnulacion);
        recibesAnuladosBeans.setAutorizado(Autorizado);
        recibesAnuladosBeans.setMotivo(Motivo);
        if (recibesAnuladosBeans.GuardarReciboAnulado() == true) {
            recibesBeans.setIdRecibo(IdRecibo);
            if (recibesBeans.GuardarReciboAnulado() == true) {
                ActualizarTablasConAnulacion();
                JOptionPane.showMessageDialog(this, "Se guardo la anulacion del recibo", "Mensaje", JOptionPane.INFORMATION_MESSAGE);
            } else {
                JOptionPane.showMessageDialog(this, "No se guardo la anulacion del recibo\nIntentelo nuevamente\nRevise recibesBeans.GuardarReciboAnulado()", "Mensaje", JOptionPane.INFORMATION_MESSAGE);
                return;
            }


        } else {
            JOptionPane.showMessageDialog(this, "No se guardo la anulacion del recibo\nIntentelo nuevamente\nRevise recibesAnuladosBeans.GuardarReciboAnulado()", "Mensaje", JOptionPane.INFORMATION_MESSAGE);
            return;
        }

        jButtonAnular.setEnabled(false);


    } catch (Exception ex) {
        sesion.MostrarMensajeError("Error", "Boton Guardar()\nError " + ex.getMessage().toString());

    }
}//GEN-LAST:event_jButtonAnularActionPerformed

    /**
     * @param args the command line arguments
     */
    public static void main(String args[]) {
        java.awt.EventQueue.invokeLater(new Runnable() {

            public void run() {
                new RecibosAnularFrame().setVisible(true);
            }
        });
    }

    /*
     * 
     *verifica si ya se pago la placa para este año 
     * 
     */
    public void CargarRecibos() {
        try {

            if (recibesBeans.getId().equals("")) {
                JOptionPane.showMessageDialog(this, "Este recibo no tiene indicado quien lo pago", "Mensaje", JOptionPane.INFORMATION_MESSAGE);
                return;
            }


            this.jTextFieldIdPagador.setText(recibesBeans.getId());

            this.jTextFieldNombrePagador.setText(recibesBeans.getNombrePagador());
            this.jTextFieldExoneracion.setText(recibesBeans.getIdExonerado());
            this.jTextFieldTipoRecibo.setText(recibesBeans.getTipoRecibo());

            //String ltotal = String.valueOf(recibesBeans.getTotalPagado());
            jTextFieldTotalPago.setText(sesion.getFormateador().format(recibesBeans.getTotalPagado()));
//ltotal = String.valueOf(recibesBeans.getTotalExonerado());
            jTextFieldTotalExonerado.setText(sesion.getFormateador().format(recibesBeans.getTotalExonerado()));
            jTextFieldNombreFuncionario.setText(recibesBeans.getNombreFuncionario());
            jTextFieldAutorizadoPor.setText("");
            jTextAreaMotivo.setText("");
            this.Id = recibesBeans.getId();
            this.TipoId = recibesBeans.getTipoId();
            this.TipoId = this.TipoId.trim();
            this.TipoRecibo = recibesBeans.getTipoRecibo();
            this.TipoRecibo = this.TipoRecibo.trim();
            this.TotalPagado =recibesBeans.getTotalPagado();
            this.TotalExonerado =recibesBeans.getTotalExonerado();
            CargarDetallesRecibos();
            repaint();


        } catch (Exception ex) {
            sesion.MostrarMensajeError("Error ", "CargarRecibos()\n " + ex.getMessage().toString());
        }
    }

    private void Limpiar() {
        try {
            jTextFieldIdPagador.setText("");
            jTextFieldNombrePagador.setText("");

            jTextFieldExoneracion.setText("");
            jTextFieldRecibo.setText("");
            jTextFieldTotalPago.setText("");
            jTextFieldTotalExonerado.setText("");
            jTextFieldNombreFuncionario.setText("");
            jTextFieldAutorizadoPor.setText("");
            jTextAreaMotivo.setText("");
            LimpiarTable();
            jButtonAnular.setEnabled(false);
        } catch (Exception ex) {
            sesion.MostrarMensajeError("Error ", "Limpiar()\n " + ex.getMessage().toString());
        }
    }

    private void LimpiarTable() {
        try {
            //limpiar  el jXTable

            boolean control = false;
            while (control == false) {
                int n = jXTable1.getRowCount();
                //System.out.println("n" + n);
                if (n <= 0) {
                    control = true;
                } else {
                    modelo.removeRow(0);
                }

            }//while
        } catch (Exception ex) {
            sesion.MostrarMensajeError("Error ", "LimpiarTable()\n " + ex.getMessage().toString());
        }
    }

    /*
     *
     *Cargar
     *
     */
    private void AgregarFila() {
        try {
            Object[] filas = new Object[13]; // Hay tres columnas en la tabla
            rowComentario = "";
            filas[0] = new Boolean(false);
            filas[1] = rowIdRegimen;
            filas[2] = rowRegimen;
            filas[3] = rowSaldoAnterior;
            filas[4] = rowCantidad;
            filas[5] = rowPago;
            filas[6] = rowSaldo;
            filas[7] = rowExoneracion;
            filas[8] = rowEstatus;
            filas[9] = rowPeriodo;
            filas[10] = rowValor;
            filas[11] = rowSoloMorosidad;
            filas[12] = rowComentario;




            modelo.addRow(filas);
        } catch (Exception ex) {
            sesion.MostrarMensajeError("Error ", "AgregarFila()\n " + ex.getMessage().toString());
        }
    }

    private void CargarDetallesRecibos() {
        try {

            recibesDetallesBeans.setIdRecibo(IdRecibo);
            recibesDetallesBeans.CargarDetallesRecibos();
            if (recibesDetallesBeans.getNumeroRegistrosLista() == - 1) {
                sesion.MostrarMensajeAdvertencia("Mensaje ", "No hay detalles de este recibo");
                return;
            }
            for (int i = 0; i <= recibesDetallesBeans.getNumeroRegistrosLista(); i++) {


                rowIdRegimen = recibesDetallesBeans.getListaIdRegimen().get(i);
                rowRegimen = recibesDetallesBeans.getListaRegimen().get(i);
                rowValor = recibesDetallesBeans.getListaValor().get(i);
                rowPago = recibesDetallesBeans.getListaPago().get(i);
                rowCantidad = recibesDetallesBeans.getListaCantidad().get(i);
                rowExoneracion = recibesDetallesBeans.getListaExoneracion().get(i);
                rowSaldo = recibesDetallesBeans.getListaSaldo().get(i);
                rowSaldoAnterior = recibesDetallesBeans.getListaSaldoAnterior().get(i);
                rowEsRecargo = recibesDetallesBeans.getListaEsRecargo().get(i);
                rowComentario = recibesDetallesBeans.getListaComentario().get(i);
                rowEstatus = recibesDetallesBeans.getListaEstatus().get(i);
                rowPeriodo = recibesDetallesBeans.getListaPeriodo().get(i);
                rowSoloMorosidad = recibesDetallesBeans.getListaSoloMorosidad().get(i);
                AgregarFila();
            }
            jButtonAnular.setEnabled(true);
        } catch (Exception ex) {
            sesion.MostrarMensajeError("Error ", "AgregarFila()\n " + ex.getMessage().toString());
        }
    }

    private void ActualizarTablasConAnulacion() {
        try {

            ActualizarTablasMensualesAnuales();

            int n = jXTable1.getRowCount();
            if (n < 0) {
                JOptionPane.showMessageDialog(this, "No existen registros en la tabla ", "Error", JOptionPane.WARNING_MESSAGE);
                return;
            }

            int contadorRegistrosRecibos = -1;

            for (int i = 0; i < n; i++) {
                this.idRegimen = String.valueOf(jXTable1.getValueAt(i, 1));

                String Estatus = String.valueOf(jXTable1.getValueAt(i, 8));
                if (Estatus == null) {
                    Estatus = "";
                }
                Estatus = Estatus.trim();

                String Periodo = String.valueOf(jXTable1.getValueAt(i, 9));
                if (Periodo == null) {
                    Periodo = "";
                }
                Periodo = Periodo.trim();

                String SSoloMorosidad = String.valueOf(jXTable1.getValueAt(i, 11));
                if (SSoloMorosidad.equals("")) {
                    this.SoloMorosidad = 0.0;
                } else {
                    this.SoloMorosidad = Double.parseDouble(SSoloMorosidad);
                }
                String SSaldoAnterior = String.valueOf(jXTable1.getValueAt(i, 3));
                if (SSaldoAnterior.equals("")) {
                    this.SaldoAnterior = 0.0;
                } else {
                    this.SaldoAnterior = Double.parseDouble(SSaldoAnterior);
                }


                if (Estatus.equals("vigenciasexpiradas")) {
                    ActualizarVigenciasExpiradas();
                }
                if (Estatus.equals("morosidad")) {
                    ActualizarMorosidad();
                    //actualizar la morosidad
                }
                if (Estatus.equals("recargo")) {
                    ActualizarRecargos();
                    //actualizar el recargo
                    //usar this.SaldoAnterior
                }


            }


            if (TipoRecibo.equals("bicicletaspagoplacas")) {
                return;
            }
            //comercios
            if (TipoRecibo.equals("comerciosfijo")) {
                //no se hace nada
                return;
            }
            if (TipoRecibo.equals("comerciosarreglopago")) {
                AnularRecibosArregloPago();
                return;
            }
             if (TipoRecibo.equals("comerciosinscripcion")) {
                comerciosInscripcionBeans.setIdComercio(this.Id);
                comerciosInscripcionBeans.AnularInscripcion();
                return;
            }


            //contribuyentes
            if (TipoRecibo.equals("contribuyentesfijo")) {
               //no se hace nada
                return;
            }
            if (TipoRecibo.equals("contribuyentesarreglopago")) {
                AnularRecibosArregloPago();
                return;
            }



            //remolques

            if (TipoRecibo.equals("remolquespagoplaca")) {
                return;
            }
            if (TipoRecibo.equals("remolquespagoplacaatrasados")) {
                return;
            }
            if (TipoRecibo.equals("remolquesinscripcion")) {
                AnularInscripcionRemolques();
                return;
            }
            //vehiculos
            if (TipoRecibo.equals("vehiculoscertificacion")) {
                return;
            }
            if (TipoRecibo.equals("vehiculospagoplaca")) {
                 AnularPagoPlacaVehiculo();
                return;
            }
            if (TipoRecibo.equals("vehiculospagoplacaatrasados")) {
                return;
            }
            if (TipoRecibo.equals("vehiculosinscripcion")) {
                AnularInscripcionVehiculo();
                return;
            }


        } catch (Exception ex) {
            sesion.MostrarMensajeError("Error ", "AgregarFila()\n " + ex.getMessage().toString());
        }
    }

    private void ActualizarTablasMensualesAnuales() {
        try {
            pagosMensualesBeans.setIdMunicipio(sesion.getIdmunicipio());
            pagosMensualesBeans.setIdRecibo(IdRecibo);
            pagosMensualesBeans.ActualizarMesAnulado();

            pagosAnualesBeans.setIdMunicipio(sesion.getIdmunicipio());
            pagosAnualesBeans.setIdRecibo(IdRecibo);
            pagosAnualesBeans.ActualizarAnioAnulado();

        } catch (Exception ex) {
            sesion.MostrarMensajeError("Error ", "ActualizarTablasMensualesAnuales()\n " + ex.getMessage().toString());
        }
    }

    private void ActualizarVigenciasExpiradas() {
        try {
            vigenciasExpiradasBeans.setIdMunicipio(sesion.getIdmunicipio());
            vigenciasExpiradasBeans.setId(this.Id);
            vigenciasExpiradasBeans.setTipoId(this.TipoId);
            vigenciasExpiradasBeans.setAnio(this.AnioRecibo);
            vigenciasExpiradasBeans.setIdRegimen(idRegimen);
            vigenciasExpiradasBeans.setMorosidadActual(this.SaldoAnterior);
            vigenciasExpiradasBeans.ActualizarVigenciaAnulada();

        } catch (Exception ex) {
            sesion.MostrarMensajeError("Error ", "ActualizarVigenciasExpiradas()\n " + ex.getMessage().toString());
        }
    }

    private void ActualizarRecargos() {
        try {
             recargoMensualBeans.setIdMunicipio(sesion.getIdmunicipio());
            recargoMensualBeans.setId(this.Id);
            recargoMensualBeans.setTipoId(this.TipoId);
            recargoMensualBeans.setAnio(this.AnioRecibo);
            recargoMensualBeans.setIdRegimen(idRegimen);
            recargoMensualBeans.setRecargoActual(this.SaldoAnterior);
            recargoMensualBeans.ActualizarRecargoAnulado();


        } catch (Exception ex) {
            sesion.MostrarMensajeError("Error ", "ActualizarRecargos()\n " + ex.getMessage().toString());
        }
    }

        private void ActualizarMorosidad() {
        try {
            morosidadMensualBeans.setIdMunicipio(sesion.getIdmunicipio());
            morosidadMensualBeans.setId(this.Id);
            morosidadMensualBeans.setTipoId(this.TipoId);
            morosidadMensualBeans.setAnio(this.AnioRecibo);
            morosidadMensualBeans.setIdRegimen(idRegimen);
            morosidadMensualBeans.setSaldoActual(this.SoloMorosidad);
            morosidadMensualBeans.ActualizarMorosidadAnulado();
          
        } catch (Exception ex) {
            sesion.MostrarMensajeError("Error ", "ActualizarMorosidad()\n " + ex.getMessage().toString());
        }
    }

  

    private void AnularInscripcionRemolques() {
        try {
            if (sesion.Conectar() == false) {
                JOptionPane.showMessageDialog(this, "No se pudo establecer la conexion", "Mensaje", JOptionPane.INFORMATION_MESSAGE);
                return;
            }
            String sql = "update remolques set pagoinscripcion='si' where idmunicipio = ? and idremolque = ? and idrecibo=? and activo='si'";

            PreparedStatement prest1 = sesion.con.prepareStatement(sql);
            prest1.setString(1, sesion.getIdmunicipio()); //placa
            prest1.setInt(2, Integer.parseInt(this.Id));
            prest1.setInt(3, this.IdRecibo);
            int count1 = prest1.executeUpdate();


            sql = "update  remolquesinscripcion set idmunicipio =? and idremolque=? and idrecibo=? ";
            PreparedStatement prest = sesion.con.prepareStatement(sql);
            prest.setString(1, sesion.getIdmunicipio());
            prest.setInt(2, Integer.parseInt(this.Id)); //
            prest.setInt(3, this.IdRecibo);

            int count = prest.executeUpdate();
            sesion.con.close();


        } catch (Exception ex) {
            System.out.println("Error" + ex);
            JOptionPane.showMessageDialog(this, "AnularInscripcionRemolques()\nError " + ex.getMessage(), "Error", JOptionPane.ERROR_MESSAGE);
        }

    }

    private void AnularInscripcionVehiculo() {
        try {
            if (sesion.Conectar() == false) {
                JOptionPane.showMessageDialog(this, "No se pudo establecer la conexion", "Mensaje", JOptionPane.INFORMATION_MESSAGE);
                return;
            }
            String sql = "update  vehicles set pagoinscripcion='no' where idmunicipio = ? and idvehiculo = ? and activo='si'";

            PreparedStatement prest1 = sesion.con.prepareStatement(sql);
            prest1.setString(1, sesion.getIdmunicipio()); //placa
            prest1.setInt(2, Integer.parseInt(this.Id));
            int count1 = prest1.executeUpdate();


            sql = "update vehiclesinscripcion  set activo ='no' where idvehiculo = ? and idrecibo=? and idmunicipio=? and activo='si'";
            PreparedStatement prest = sesion.con.prepareStatement(sql);

            prest.setString(1, this.Id); //
            prest.setInt(2, this.IdRecibo);
            prest.setString(3, sesion.getIdmunicipio());
            int count = prest.executeUpdate();
            sesion.con.close();


        } catch (Exception ex) {
            System.out.println("Error" + ex);
            JOptionPane.showMessageDialog(this, "AnularInscripcionVehiculo()\nError " + ex.getMessage(), "Error", JOptionPane.ERROR_MESSAGE);
        }

    }
 private void AnularPagoPlacaVehiculo() {
        try {
            if (sesion.Conectar() == false) {
                JOptionPane.showMessageDialog(this, "No se pudo establecer la conexion", "Mensaje", JOptionPane.INFORMATION_MESSAGE);
                return;
            }
            String sql = "update  vehiclespagosplacas set activo='no' where idmunicipio = ? and idvehiculo = ? and idrecibo=? and activo='si' ";

            PreparedStatement prest1 = sesion.con.prepareStatement(sql);
            prest1.setString(1, sesion.getIdmunicipio()); //placa
            prest1.setInt(2, Integer.parseInt(this.Id));
              prest1.setInt(3, this.IdRecibo);
            int count1 = prest1.executeUpdate();


          
            sesion.con.close();


        } catch (Exception ex) {
            System.out.println("Error" + ex);
            JOptionPane.showMessageDialog(this, "AnularPagoPlacaVehiculo()\nError " + ex.getMessage(), "Error", JOptionPane.ERROR_MESSAGE);
        }

    }
       private void AnularRecibosArregloPago() {
        try {
             arregloPagoBeans.setIdMunicipio(sesion.getIdmunicipio());
            arregloPagoBeans.setId(this.Id);
            arregloPagoBeans.setTipoId(this.TipoId);
            arregloPagoBeans.setAnio(this.AnioRecibo);
            this.SaldoAnterior = this.TotalPagado + this.TotalExonerado;
            arregloPagoBeans.setSaldoActual(this.SaldoAnterior);
            arregloPagoBeans.ActualizarArregloPagoAnulado();


        } catch (Exception ex) {
            sesion.MostrarMensajeError("Error ", "ActualizarRecargos()\n " + ex.getMessage().toString());
        }
    }
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton jButtonAnular;
    private javax.swing.JButton jButtonLimpiar;
    private javax.swing.JButton jButtonRegresar;
    private javax.swing.JButton jButtonRegresar2;
    private javax.swing.JFormattedTextField jFormattedTextFieldFecha;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel10;
    private javax.swing.JLabel jLabel18;
    private javax.swing.JLabel jLabel2;
    private javax.swing.JLabel jLabel3;
    private javax.swing.JLabel jLabel4;
    private javax.swing.JLabel jLabel5;
    private javax.swing.JLabel jLabel6;
    private javax.swing.JLabel jLabel7;
    private javax.swing.JLabel jLabel8;
    private javax.swing.JLabel jLabel9;
    private javax.swing.JPanel jPanelFondo;
    private javax.swing.JScrollPane jScrollPane1;
    private javax.swing.JScrollPane jScrollPane2;
    private javax.swing.JSeparator jSeparator1;
    private javax.swing.JTextArea jTextAreaMotivo;
    private javax.swing.JTextField jTextFieldAutorizadoPor;
    private javax.swing.JTextField jTextFieldExoneracion;
    private javax.swing.JTextField jTextFieldIdPagador;
    private javax.swing.JTextField jTextFieldNombreFuncionario;
    private javax.swing.JTextField jTextFieldNombrePagador;
    private javax.swing.JTextField jTextFieldRecibo;
    private javax.swing.JTextField jTextFieldTipoRecibo;
    private javax.swing.JTextField jTextFieldTotalExonerado;
    private javax.swing.JTextField jTextFieldTotalPago;
    private org.jdesktop.swingx.JXDatePicker jXDatePickerFechaAnulacion;
    private org.jdesktop.swingx.JXTable jXTable1;
    // End of variables declaration//GEN-END:variables
}
